package com.xiaode.controller.admin.user;

import cn.hutool.crypto.SecureUtil;

import java.util.List;

import com.jfinal.kit.Ret;
import com.jfinal.plugin.redis.Redis;
import com.xiaode.common.constant.Const;
import com.xiaode.common.model.Admin;
import com.xiaode.common.model.UserAccount;

public class UserService {

	public Ret changeInfo(Integer accountId, String newPassword) throws Exception {
		
		UserAccount userAccount = UserAccount.dao.findById(accountId);
		newPassword = SecureUtil.md5(newPassword + userAccount.getId() + Const.salt);
		UserAccount ua = new UserAccount();
		ua.setId(accountId);
		ua.setPassword(newPassword);
		ua.update();
		
		Redis.use().del(Const.user.loginAdmin + accountId);
		return Ret.ok();

	}

	public Ret findAdmin() {
		List<Admin> admins = Admin.dao.find("SELECT id,name,job_num FROM admin WHERE isDele = 0 AND user_type = 1");
		return Ret.ok("admins", admins);
	}



}
